package test.cumulativeProtocol.server;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

import com.mahjong.server.mina.protocol.AbsMessageProtocol;
import com.mahjong.server.mina.protocol.DataBuf;
import com.mahjong.server.protocolHandler.user.RegisterResp;

/**
 * 
 * @author Simple
 * @date 2013-3-5 上午10:58:27
 * @Description Server端消息处理
 */
public class TServerHandler extends IoHandlerAdapter {

  @Override
  public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
    cause.printStackTrace();
  }

  @Override
  public void messageReceived(IoSession session, Object message) throws Exception {
    AbsMessageProtocol req=(AbsMessageProtocol)message;
    short pn=req.getProtocolNum();
    DataBuf buf=req.getDataBuf();
    switch(pn) {
      case 0x0001:
        String username=buf.getString();
        String password=buf.getString();
        String mobile=buf.getString();
        System.out.println("[" + pn + "]协议,收到的数据为:" + username + "-" + password + "-" + mobile);
        session.write(new RegisterResp((byte)1));
        break;
    }
  }

  @Override
  public void messageSent(IoSession session, Object message) throws Exception {
    super.messageSent(session, message);
  }

  @Override
  public void sessionClosed(IoSession session) throws Exception {
    super.sessionClosed(session);
  }

  @Override
  public void sessionCreated(IoSession session) throws Exception {
    super.sessionCreated(session);
  }

  @Override
  public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
    super.sessionIdle(session, status);
  }

  @Override
  public void sessionOpened(IoSession session) throws Exception {
    super.sessionOpened(session);
  }
}
